package jdbc;

import com.mysql.cj.protocol.Resultset;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args) {
        try (
            Connection conn = DBUtil.getConnection())
        {
            System.out.println("与数据库连接成功！");
            String sql = "SELECT id,name,salary,title " +
                         "FROM teacher ";
            Statement stat = conn.createStatement();
            ResultSet rs = stat.executeQuery(sql);
            while(rs.next()){
                int id = rs.getInt("id");
                String name = rs.getString("name");
                int salary = rs.getInt("salary");
                String title = rs.getString("title");
                System.out.println(id + " " + name + " " + salary + " " + title);
            }



        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
